dash_clocks_for_today = {
		  id: "dash_clocks_for_today"
		, title: "Clocks for today" 
		, width: "400px"
		, height: "150px"
		, attach_to_panel: 2
		, content_function: create_clocks_for_today
	};

dash_summmary_for_today = {
		  id: "dash_summary_for_today"
		, title: "Summary for today" 
		, width: "400px"
		, height: "150px"
		, attach_to_panel: 2
		, content_function: create_summary_for_today
	};

dash_type_of_workers = {
		  id: "dash_type_of_workers"
		, title: "Type of workers in past 2 weeks" 
		, width: "400px"
		, height: "235px"
		, attach_to_panel: 2
		, content_function: create_type_of_workers
	};
	
dash_head_count = {
		  id: "dash_head_count"
		, title: "People on site over the past 2 weeks" 
		, width: "650px"
		, height: "400px"
		, attach_to_panel: 1
		, content_function: create_head_count
	};

dash_getting_started = {
		  id: "dash_getting_started"
		, title: "GETTING STARTED" 
		, width: "650px"
		, height: "200px"
		, attach_to_panel: 1
		, content_function: create_getting_started
	};
//----------------------------------------------------------------------
function create_clocks_for_today(container, options){
	var table = $("<table border=0></table>");
	var tr = $("<tr></tr>").addClass("ui-widget-header");
	table.append($("<thead></thead>").append(tr));
	tr.append("<th>Date Created</th>");
	tr.append("<th>Story</th>");
	tr.append("<th>Notes</th>");
	
	update_table_format(table);

	return table;
}

function create_summary_for_today(container, options){
	var container = $(container);
	var request = {
			  ajax_url			: panel_list["home_page"].ajax_url
			, server_call		: "home_page_summary_for_today"
			, data				: {
					attend_date		: $.format.date((new Date()), "dd MMMM yyyy") //"05 January 2012"
				}
		}
	get_server_data(request, function(data){
		var table	= $("<table style='width:100%;'>");
		var tr		= $("<tr>").appendTo(table);
		var col		= $("<td>").html("Absent").addClass("label").appendTo(tr);
		var col		= $("<td>").html(data.absent).appendTo(tr);
		
		var tr		= $("<tr>").appendTo(table);
		var col		= $("<td>").html("Leave").addClass("label").appendTo(tr);
		var col		= $("<td>").html(data.leave).appendTo(tr);
		
		var tr		= $("<tr>").appendTo(table);
		var col		= $("<td>").html("At Work").addClass("label").appendTo(tr);
		var col		= $("<td>").html(data.at_work).appendTo(tr);
		
		container.children().remove();
		container.append(table);
		update_table_format(table);
	});
}

function create_head_count(container, options){
	var container = $(container);
	
	var request = {
			  ajax_url			: panel_list["home_page"].ajax_url
			, server_call		: "home_page_head_count"
			, data				: {
					attend_date		: $.format.date((new Date()), "dd MMMM yyyy") //"05 January 2012"
				}
		}
	get_server_data(request, function(data){
		var chart_data = [];
		
		$(data).each(function(){
			chart_data.push([
				  //this.cnt
				 $.format.date(Date.createFromFirebird(this.datecreated), "dd MMMM yyyy")
				, this.cnt
			]);
		});
		//__create_barchart(container, chart_data);
		__create_line_chart(container, chart_data);
	});
}

function create_type_of_workers(container, options){
	var container = $(container);
	
	var request = {
			  ajax_url			: panel_list["home_page"].ajax_url
			, server_call		: "home_page_type_of_workers"
			, data				: {
					attend_date		: $.format.date((new Date()), "dd MMMM yyyy") //"05 January 2012"
				}
		}
	get_server_data(request, function(data){
		var chart_data = [];
		
		$(data).each(function(){
			chart_data.push([
				  this.cnt
				, this.name
				//, this.cnt
			]);
		});

		__create_barchart(container, chart_data);
		//__create_line_chart(container, chart_data);
	});
}

function create_getting_started(container, options){
	var btn_set = $("<div>");
	
	var btn = $("<div>")
				.appendTo(btn_set)
				.html("Do some reading...")
				//.button()
				.click(function(){
					window.open("../dokuwiki/doku.php?id=getting_started");
				});

	edit_clients.type = "create";
	edit_clients.eventName = "click";
	var btn = $("<div>")
				.appendTo(btn_set)
				.html("Create a client profile")
				//.button()
				.lookup_form(edit_clients, function(data){
						hide_title();
						//IF THERE IS NO DEFAULT CLIENT THEN WE NEED TO TRY AND SWITCH TO IT
						//TO DO THIS WE DO A ADMINISTRATOR CHECK-STATUS. IT WILL THEN TRIGGER
						//ALL THE NECESSARY FUNCTIONS
						//panel_list["administrators"].check_status();
						load_active_clients();
					});

	edit_employee.server_call = edit_employee.server_call_create;
	var btn = $("<div>")
				.appendTo(btn_set)
				.html("Import Some Employees")
				//.button()
				.import_data(edit_employee);
				
	edit_tna_clocks.server_call = edit_tna_clocks.server_call_create;
	var btn = $("<div>")
				.appendTo(btn_set)
				.html("Import Some Clocks")
				//.button()
				.import_data(edit_tna_clocks);
	
	var btn = $("<div>")
				.appendTo(btn_set)
				.html("Edit My Profile")
				//.button()
				.click(function(){
					panel_list["administrators"].show();
				});
	
	var btn = $("<div>")
				.appendTo(btn_set)
				.html("Send Me Notifications")
				//.button()
				.click(function(){
					panel_list["notifications"].show();
				});
				
	btn_set.find("div").each(function(){
		var $this = $(this);
		$this.css({
			  "width"		: "150px"
			, "padding"		: "10px"
			, "border"		: "5px solid #6C6C6C"
			, "float"		: "left"
			, "margin"		: "10px"
			, "cursor"		: "default"
			, "background"	: "white"
			, "color"		: "#6C6C6C"
			, "text-align"	: "center"
		});
		
		
		$this
			.unbind("hover")
			.hover(
				function(){
					$(this).css({
						  "cursor"		: "pointer"
						, "background"	: "#6C6C6C"
						, "color"		: "white"
					});
				}
				, function(){
					$(this).css({
						  "cursor"		: "default"
						, "background"	: "white"
						, "color"		: "#6C6C6C"
					});
				}
			);
		
		$this.addClass("ui-widget ui-corner-all");
	});
	//btn_set.buttonset();
	return btn_set;
}

//----------------------------------------------------------------------
// HELPER FUNCTIONS
//----------------------------------------------------------------------
function __create_line_chart(chart_area, data){
	$(chart_area).children().remove();
	var parent = $(chart_area).parent();
	$(chart_area).css({
		  width		: (parseFloat(parent.css("width"))*0.98) + "px"
		, height	: (parseFloat(parent.css("height"))*0.85) + "px"
	});
	if (data.length == 0) return;
	$.jqplot.config.enablePlugins = true;
	$.jsDate.config.defaultCentury = 2000;
	var plot1 = $.jqplot($(chart_area).attr("id"), [data], {
        // Turns on animatino for all series in this plot.
        animate: true,
        // Will animate plot on calls to plot1.replot({resetAxes:true})
        animateReplot: true,
        cursor: {
            show: false
            //zoom: true,
            //looseZoom: true,
            //showTooltip: false
        },
        series:[
            /*{
                pointLabels: {
                    show: true
                    
                },
                showHighlight: true,
                yaxis: 'y2axis',
                rendererOptions: {
                    // Speed up the animation a little bit.
                    // This is a number of milliseconds. 
                    // Default for bar series is 3000. 
                    animation: {
                        speed: 2500
                    },
                    //barWidth: 15,
                    //barPadding: -15,
                    //barMargin: 0,
                    highlightMouseOver: false
                }
            },*/
            {
                rendererOptions: {
                    // speed up the animation a little bit.
                    // This is a number of milliseconds.
                    // Default for a line series is 2500.
                    animation: {
                        speed: 2000
                    }
                }
            }
        ],
        axesDefaults: {
            pad: 0
        },
        axes: {
            // These options will set up the x axis like a category axis.
            xaxis: {
				min: data[0][0],
				max: data[data.length-1][0],
				numberTicks: 14,
                //tickInterval: 1,
                drawMajorGridlines: true,
                drawMinorGridlines: true,
                drawMajorTickMarks: true,
                renderer:$.jqplot.DateAxisRenderer,
                tickOptions: {
					  formatString: "%d/%m"
					, labelPosition: "start"
					//, showMark: true
				},
                rendererOptions: {
					  tickInset: 0.2
					, majorTicks: 1
					, alignTicks: true
				}
            },
            yaxis: {
                tickOptions: {
                    formatString: "%'d"
                },
                rendererOptions: {
                    forceTickAt0: true
                }
            }
        },
        highlighter: {
              show				: true
            , showLabel			: true
            //, tooltipAxes		: 'y'
            , sizeAdjust		: 7.5
            //, tooltipLocation	: 'ne'
        }
    });
}

function __create_barchart(chart_area, data){
	$(chart_area).children().remove();
	if (data.length == 0) return;
	var parent = $(chart_area).parents("div");
	$(chart_area).css({
		  "width"	: (0.9*parseFloat(parent.css("width")))
		, "height"	: (0.9*parseFloat(parent.css("height")))
	});
	if (data.length == 0) return;
	var plot1 = $.jqplot ($(chart_area).attr("id"), [data], {
		// Turns on animatino for all series in this plot.
        animate: true,
        // Will animate plot on calls to plot1.replot({resetAxes:true})
        animateReplot: true,
        seriesDefaults: {
            renderer:$.jqplot.BarRenderer,
            // Show point labels to the right ('e'ast) of each bar.
            // edgeTolerance of -15 allows labels flow outside the grid
            // up to 15 pixels.  If they flow out more than that, they
            // will be hidden.
            pointLabels: { show: false, location: 'n', edgeTolerance: -15 },
            // Rotate the bar shadow as if bar is lit from top right.
            shadowAngle: 135,
            // Here's where we tell the chart it is oriented horizontally.
            rendererOptions: {
                barDirection: 'horizontal'
            }
        },
        axes: {
            yaxis: {
                renderer: $.jqplot.CategoryAxisRenderer
            }
        }
		});
}
